package cx.xuyang.demo;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import cx.xuyang.view.SelectHistoryMenu;
import cx.xuyang.view.SelectHistoryMenu.OnSelectHistoryMenuItemClickListener;
import cx.xuyang.view.SelectHistoryMenu.OnSelectHistoryMenuItemDeleteListener;
import cx.xuyang.view.SelectHistoryMenu.OnSelectHistoryMenuItemLongClickListener;

public class MainActivity extends Activity {
	private SelectHistoryMenu mMenu;
	private Button buttn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		buttn=(Button) findViewById(R.id.button1);
		buttn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Toast.makeText(getBaseContext(), "添加了一个", 0).show();
				mMenu.addItem("333");
			}
		});
		
		mMenu=(SelectHistoryMenu) findViewById(R.id.select_history_menu);
		ArrayList<String> data=new ArrayList<String>();
		data.add("毛泽东思想");
		data.add("侏罗纪公园");
		data.add("春");
		data.add("夏");
		data.add("中华人民共和国史");
		mMenu.setDatas(data);
		
		mMenu.setOnSelectHistoryMenuItemClickListener(new OnSelectHistoryMenuItemClickListener() {
			
			@Override
			public void onItemClick(View v) {
				Toast.makeText(getBaseContext(), ((TextView)v).getText()+" 被点击了", 0).show();
			}
		});
		
		mMenu.setOnMenuItemDeleteListener(new OnSelectHistoryMenuItemDeleteListener() {
			
			@Override
			public void onDeleteClick(String v) {
				Toast.makeText(getBaseContext(),v+"被删除了", 0).show();
			}
		});
		
		mMenu.setOnMenuItemLongClickListener(new OnSelectHistoryMenuItemLongClickListener() {
			
			@Override
			public void onLongClick(View v) {
				Toast.makeText(getBaseContext(), ((TextView)v).getText()+" 被长按了", 0).show();
			}
		});
	}

}
